package graphics.raytracing;

import graphics.datastructures.Triangle;
import drawing.DrawingEngine;

public class SimpleWindowWithCallback implements Window<Triangle> {
	Window<Triangle> window;

	public float[] getCenter() {
		return window.getCenter();
	}

	DrawingEngine _engine;
	private int count = 0;
	private int redraw;

	public SimpleWindowWithCallback(float[] origin, float[] vx, float[] vy,
			int xmax, int ymax, LightSource source, DrawingEngine engine,
			int red, CameraPosition pos) {
		window = new SimpleWindow(origin, vx, vy, xmax, ymax, source, pos);
		_engine = engine;
		redraw = red;
	}

	public Ray determineRay(int x, int y) {
		return window.determineRay(x, y);
	}

	public float[] getColor(int x, int y) {
		return window.getColor(x, y);
	}

	public void color(int x, int j, float[] color) {
		window.color(x, j, color);
		int y = window.xy()[1] - j;
		_engine.setPixel(x, y, color);
		count++;
		if (count % redraw == 0) {
			_engine.notifyChange();
		}
	}

	public int[] xy() {
		return window.xy();
	}

	public float[][][] getView() {
		return window.getView();
	}

	public void waitForSet() {
		window.waitForSet();
		System.out.println("notifiedf");
		_engine.notifyChange();
	}

	@Override
	public void reset() {
		window.reset();
	}

	@Override
	public void setShader(Shader s) {
		window.setShader(s);

	}

	@Override
	public void color(int[] _xy, CastResult result) {
		color(_xy[0], _xy[1], window.getShader().shade(result));

	}

	@Override
	public Shader getShader() {

		return window.getShader();
	}

}
